<template>
  <div class="container-content">
    <el-form
      ref="elForm"
      :model="formData"
      :rules="rules"
      size="medium"
      label-width="150px"
    >
      <el-collapse v-model="activeName" @change="handleClick">
        <el-collapse-item title="基础" name="basic">
          <!-- <el-form-item label="编码" prop="bizCode">
            <el-input
              v-model="formData.bizCode"
              placeholder=""
              clearable
              :style="{ width: '100%' }"
            >
            </el-input>
          </el-form-item> -->
          <el-form-item label="名称" prop="title">
            <el-input
              v-model="formData.title"
              placeholder="请输入名称"
              clearable
              :style="{ width: '100%' }"
            ></el-input>
          </el-form-item>
          <el-form-item label="结算方式类别" prop="settlementCategory">
            <el-select
              v-model="formData.settlementCategory"
              placeholder="请选择结算方式类别"
              clearable
              :style="{ width: '100%' }"
            >
              <el-option
                v-for="(item, index) in settlementCategoryOptions"
                :key="index"
                :label="item.label"
                :value="item.value"
                :disabled="item.disabled"
              ></el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="业务分类" prop="bizClassification">
            <el-select
              v-model="formData.bizClassification"
              placeholder="请选择业务分类"
              clearable
              :style="{ width: '100%' }"
            >
              <el-option
                v-for="(item, index) in bizClassificationOptions"
                :key="index"
                :label="item.label"
                :value="item.value"
                :disabled="item.disabled"
              ></el-option>
            </el-select>
          </el-form-item>

          <el-form-item label="账户类型" prop="accountType" v-if="formData.bizClassification=='2'">
            <el-select
              v-model="formData.accountType"
              placeholder="请选择账户类型"
              clearable
              :style="{ width: '100%' }"
            >
              <el-option
                v-for="(item, index) in dataStatusOptions"
                :key="index"
                :label="item.label"
                :value="item.value"
                :disabled="item.disabled"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="票据类型" prop="billType" v-if="formData.bizClassification=='3'">
            <el-select
              v-model="formData.billType"
              placeholder="请选择票据类型"
              clearable
              :style="{ width: '100%' }"
            >
              <el-option
                v-for="(item, index) in billTypeOptions"
                :key="index"
                :label="item.label"
                :value="item.value"
                :disabled="item.disabled"
              ></el-option>
            </el-select>
          </el-form-item>
          <el-form-item label="是否禁用" prop="isDisabled">
            <el-radio v-model="formData.isDisabled" label="1" border
              >是</el-radio
            >
            <el-radio v-model="formData.isDisabled" label="2" border
              >否</el-radio
            >
          </el-form-item>
          <el-form-item label="是否为默认结算方式" prop="isDefault">
            <el-radio v-model="formData.isDefault" label="1" border
              >是</el-radio
            >
            <el-radio v-model="formData.isDefault" label="2" border
              >否</el-radio
            >
          </el-form-item>

          <el-form-item label="是否支付手续费" prop="isPayFee">
            <el-radio v-model="formData.isPayFee" label="1" border>是</el-radio>
            <el-radio v-model="formData.isPayFee" label="2" border>否</el-radio>
          </el-form-item>
          <el-form-item label="是否支持网银付款" prop="isSupportLinePay">
            <el-radio v-model="formData.isSupportLinePay" label="1" border
              >是</el-radio
            >
            <el-radio v-model="formData.isSupportLinePay" label="2" border
              >否</el-radio
            >
          </el-form-item>
        </el-collapse-item>
      </el-collapse>
    </el-form>
  </div>
</template>
<script>
import { add } from "@/api/base/data";
import { updataKingProfitLossList,editKingBaseSettlementTypeList} from "@/api/bim/outher";
export default {
  components: {},
  props: ["id"],
  data() {
    return {
        flag:false,
      activeName: "basic",
      formData: {
        bizClassification: undefined,
        bizCode: undefined,
        dataStatus: undefined,
        isDefault: undefined,
        isDisabled: undefined,
        isPayFee: undefined,
        isSupportLinePay: undefined,
        settlementCategory: undefined,
        title: undefined,
      },
      rules: {
        bizClassification: [
          {
            required: true,
            message: "请选择业务分类",
            trigger: "change",
          },
        ],
        settlementCategory: [
          {
            required: true,
            message: "请选择结算方式类别",
            trigger: "change",
          },
        ],
        title: [
          {
            required: true,
            message: "请输入名称",
            trigger: "blur",
          },
        ],
        accountType:[
            {
            required: true,
            message: "请选择结账户类型",
            trigger: "change",
          },
        ],
        billType:[
            {
            required: true,
            message: "请选择结票据类型",
            trigger: "change",
          },
        ]
      },
      bizClassificationOptions: [
        {
          label: "现金业务",
          value: "1",
        },
        {
          label: "银行业务",
          value: "2",
        },
        {
          label: "票据业务",
          value: "3",
        },
        {
          label: "内部结算",
          value: "4",
        },
      ],
      dataStatusOptions: [
        {
          label: "银行账号",
          value: 1,
        },
        {
          label: "微信账号",
          value: 2,
        },
        {
          label: "支付宝账号",
          value: 3,
        },
      ],
      billTypeOptions:[
          {
          label: "商业承兑汇票",
          value: 1,
        },
          {
          label: "供应链票据",
          value: 2,
        },
          {
          label: "银行承兑汇票",
          value: 3,
        },
          {
          label: "信用证",
          value: 4,
        },
      ],
      isDefaultOptions: [
        {
          label: "是",
          value: 1,
        },
        {
          label: "否",
          value: 2,
        },
      ],
      isDisabledOptions: [
        {
          label: "是",
          value: 1,
        },
        {
          label: "否",
          value: 2,
        },
      ],
      isPayFeeOptions: [
        {
          label: "是",
          value: 1,
        },
        {
          label: "否",
          value: 2,
        },
      ],
      isSupportLinePayOptions: [
        {
          label: "是",
          value: 1,
        },
        {
          label: "否",
          value: 2,
        },
      ],
      settlementCategoryOptions: [
        {
          label: "现金",
          value: "1",
        },
        {
          label: "支票",
          value: "2",
        },
        {
          label: "商业承兑汇票",
          value: "3",
        },
        {
          label: "银行承兑汇票",
          value: "4",
        },
        {
          label: "本票",
          value: "5",
        },
        {
          label: "汇兑",
          value: "6",
        },
        {
          label: "信用证",
          value: "7",
        },
        {
          label: "委托收款",
          value: "8",
        },
        {
          label: "托收承付",
          value: "9",
        },
        {
          label: "汇票",
          value: "10",
        },
        {
          label: "银行汇票",
          value: "11",
        },
        {
          label: "光票托收",
          value: "13",
        },
        {
          label: "承兑交单",
          value: "14",
        },
        {
          label: "远期付款交单",
          value: "15",
        },
        {
          label: "即期付款交单",
          value: "16",
        },
        {
          label: "票汇",
          value: "17",
        },
        {
          label: "信用卡",
          value: "18",
        },
        {
          label: "微信",
          value: "19",
        },
        {
          label: "支付宝",
          value: "20",
        },
      ],
    };
  },
  computed: {},
  watch: {},
  created() {},
  mounted() {
    if (this.id != "") {
        this.flag=true
      updataKingProfitLossList(this.id).then((res) => {
        this.formData = res.data;
      });
    }
  },
  methods: {
    handleClick() {},
    submitForm(cb) {
        console.log(this.flag);
        
      if (this.flag) {
            this.$refs["elForm"].validate((valid) => {
          if (!valid) return;
          // TODO 提交表单
           this.formData.id=this.id
          editKingBaseSettlementTypeList(this.formData).then((res) => {
            if (res.code === 200) {
              cb();
              this.$message.success("修改成功");
               this.flag=false
            }
          });
        });       
      } else {
        this.$refs["elForm"].validate((valid) => {
          if (!valid) return;
          // TODO 提交表单
          add(this.formData, "KingBaseSettlementType").then((res) => {
            if (res.code === 200) {
              cb();
              this.$message.success("新增成功");
            }
          });
        });
      }
    },
    resetForm() {
      this.$refs["elForm"].resetFields();
    },
  },
};
</script>
<style></style>
